﻿CREATE PROCEDURE [dbo].[Hogar_Agente_ObtenerTodos]   
AS 
BEGIN

/*****************************************************************************************************************************************/
-- Author: Carlos Mendoza
-- Purpose:   obtener todos los agentes con sus datos
-- Returns:    ConsultaAgente
/*****************************************************************************************************************************************/ 
	
	SELECT  [AgenteId],
			[Dni],
			[Nombre],
			[Apellido],
			[Telefono],
			[Domicilio],
			[FechaBaja],
			ag.[AreaId],
			ar.[Descripcion] AS [Area],
			ag.[CargoId],
			c.[Codigo] AS [Cargo],
			ag.[PuestoId],
			p.[Descripcion] AS [Puesto],
			CASE WHEN [Activo] = 1 THEN 1 ELSE 0 END AS [Activo]
	FROM	[dbo].[Agente] ag WITH (NOLOCK)
	INNER JOIN [dbo].[Area] ar WITH (NOLOCK) ON ag.[AreaId] = ar.AreaId 
	INNER JOIN [dbo].[Cargo] c WITH (NOLOCK) ON c.[CargoId] = ag.CargoId
	INNER JOIN [dbo].[Puesto] p WITH (NOLOCK) ON p.[PuestoId] = ag.PuestoId
	ORDER BY [Apellido],[Nombre]
	
END